<template>
  <div class="user-wrapper">
    <div class="content-box">
      <lang-select />
      <router-link :to="{ name: 'dashboard' }" class="action">
        <a-icon type="home" style="font-size: 18px;vertical-align: middle;" />
      </router-link>
      <a-dropdown>
        <span class="action ant-dropdown-link user-dropdown-menu">
          <a-avatar :class="['avatar', { empty: !avatar }]" size="small" :src="avatar | imgURLFilter" icon="user" />
          <span>{{ nickname }}</span>
        </span>
        <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
          <a-menu-item>
            <router-link :to="{ name: 'accountBase' }">
              <a-icon type="user" />
              <span>{{ $t('modules.menu.account') }}</span>
            </router-link>
          </a-menu-item>
          <a-menu-item>
            <router-link :to="{ name: 'accountSecurity' }">
              <a-icon type="setting" />
              <span>{{ $t('modules.menu.changePw') }}</span>
            </router-link>
          </a-menu-item>
          <a-menu-divider />
          <a-menu-item key="3">
            <a href="javascript:;" @click="handleLogout">
              <a-icon type="logout" />
              <span>{{ $t('common.logout') }}</span>
            </a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
  </div>
</template>

<script>
import LangSelect from '@/components/tools/LangSelect';
import { mapActions, mapGetters } from 'vuex';

export default {
  name: 'UserMenu',
  components: {
    LangSelect
  },
  computed: {
    ...mapGetters(['nickname', 'avatar'])
  },
  methods: {
    ...mapActions(['Logout']),
    handleLogout() {
      this.$confirm({
        title: this.$t('common.info'),
        content: this.$t('modules.user.logoutInfo'),
        onOk: () => {
          return this.Logout().then(() => {
            window.location.reload();
          });
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
.avatar {
  &.empty {
    background-color: #ccc !important;
  }
  /deep/ i {
    color: #fff;
  }
}
</style>
